﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using WaterRevenueMS.Componnent.Common;

using WaterRevenueMS.Componnent.Entities.BasicSet;
using WaterRevenueMS.Core.Repository.BasicSet;
using WaterRevenueMS.Domain.ViewModels.BasicSet;

namespace WaterRevenueMS.Core.Service.BasicSet.Impl
{
    [Export(typeof(IConsumptionStateService))]
    public class ConsumptionStateService : CoreServiceBase, IConsumptionStateService
    {

        [Import]
        public IConsumptionStateRepository ConsumptionStateRepository { get; set; }

        public IQueryable<ConsumptionState> ConsumptionStates
        {
            get { return ConsumptionStateRepository.Entities; }
        }



        public OperationResult Insert(Domain.ViewModels.BasicSet.ConsumptionState.ConsumptionStateModel model)
        {
            var entity = new ConsumptionState
            {
                Id = model.Id,
                Yong_LZT = model.Yong_LZT,
                Zhuang_TDM = model.Zhuang_TDM,
                CreateDT = DateTime.Now,

            };
            ConsumptionStateRepository.Insert(entity);
            return new OperationResult(OperationResultType.Success, "添加成功");
        }

        public OperationResult Update(Domain.ViewModels.BasicSet.ConsumptionState.ConsumptionStateModel model)
        {
            var entity = new ConsumptionState
            {
                Id = model.Id,
                Yong_LZT = model.Yong_LZT,
                Zhuang_TDM = model.Zhuang_TDM,
                CreateDT = model.CreateTime,
                ReviseDT = DateTime.Now
            };
            ConsumptionStateRepository.Update(entity);
            return new OperationResult(OperationResultType.Success, "更新成功");
        }

        public OperationResult Delete(int Id)
        {
            var ConsumptionState = ConsumptionStates.FirstOrDefault(t => t.Id == Id);
            ConsumptionState.IsDeleted = true;

            ConsumptionStateRepository.Update(ConsumptionState);
            return new OperationResult(OperationResultType.Success, "删除成功");
        }
    }
}
